department_map = {
    # "茂南": "唐生波",
    "开发区": "阮慧",
    "茂北": "唐生波",
    "西城": "许聪",
    # "油城北": "唐生波",
    # "油城东": "唐生波",
    # "油城南东": "唐生波",
    # "油城南西": "唐生波",
    # "电白": "唐生波",
    # "滨海": "唐生波",
    # "林头": "唐生波",
    # "麻岗": "唐生波",
    # "南海": "唐生波",
    # "沙琅": "唐生波",
    # "水东": "唐生波",
    # "高州": "唐生波",
    # "大井": "唐生波",
    # "高城北": "唐生波",
    # "高城南": "唐生波",
    # "根子": "唐生波",
    # "石鼓": "唐生波",
    # "长坡": "唐生波",
    # "化州": "唐生波",
    # "合江": "唐生波",
    # "河东": "唐生波",
    # "化北": "唐生波",
    # "化河西": "唐生波",
    # "同庆": "唐生波",
    # "杨梅": "唐生波",
    # "信宜": "唐生波",
    # "北界": "唐生波",
    # "城北": "唐生波",
    # "城南": "唐生波",
    # "合水": "唐生波",
    # "钱排": "唐生波",
    # "朱砂": "唐生波",
}


import os

path = os.path
from importlib import import_module, util
from datetime import datetime
import pandas as pd

sn = import_module("switch_network")
printer = import_module("printer").IndentPrinter(indent=1)


data_path = os.environ["DATA_PATH"]


def main():
    now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    file_path = path.join(data_path, r"投诉类指标\投诉类指标.xlsx")
    df = pd.read_excel(file_path, sheet_name="部门统计")

    all_zhibiao = df.columns.tolist()
    all_zhibiao = [z for z in all_zhibiao if z not in ["部门"]]
    # printer(f"所有指标：{all_zhibiao}")

    depart = df["部门"].unique()
    depart = [d for d in depart if d in department_map]
    df.set_index("部门", inplace=True)
    df_dict = df.to_dict(orient="index")

    message_list = []
    for d in depart:

        search_text = department_map[d]

        zhibiao_dict = df_dict[d]
        zhibiao_text = []
        for k, v in zhibiao_dict.items():
            if pd.isna(v):
                v = 0
            zhibiao_text.append(f"{k}：{v}")
        all_zhibiao = "\n".join(zhibiao_text)
        message = f"截至{now}, {search_text} 您的投诉类指标如下：\n {all_zhibiao}"
        message_list.append(
            {
                "search_text": search_text,
                "message": message,
            }
        )
    printer(message_list)
    import_module("winauto").send_ydbg(message_list)


if __name__ == "__main__":
    main()
